package com.youbar.common;

import com.youbar.utils.IntegerUtil;
import com.youbar.utils.StringUtil;

import java.io.InputStream;
import java.util.Properties;

/**
 * 项目配置
 */
public class Config {

    public static int cacheTime;
    public static int loginInforTime;
    public static int fileSize;
    public static String imageType;
    public static String fileType;
    public static boolean openRegister;
    public static boolean luceneSearchNeedLogin;
    public static boolean canRepeatUrl;
    public static String mail;

    /**
     * 初始化配置信息
     */
   /* public static void init() {
        try {
            Properties properties = new Properties();
            // 使用ClassLoader加载properties配置文件生成对应的输入流
            InputStream in = SystemService.class.getResourceAsStream("/config.properties");
            // 使用properties对象加载输入流
            properties.load(in);
            Config.cacheTime = IntegerUtil.getInt(properties.getProperty(Config.getConfigCacheTime()), 3600);
            Config.loginInforTime = IntegerUtil.getInt(properties.getProperty(Config.getConfigLoginInforTime()), 3600);
            Config.fileSize = IntegerUtil.getInt(properties.getProperty(Config.getConfigFileSize()), 2);
            Config.imageType = properties.getProperty(Config.getConfigImageType());
            Config.fileType = properties.getProperty(Config.getConfigFileType());
            Config.openRegister = StringUtil.getBoolean(properties.getProperty(Config.getConfigOpenRegister()), true);
            Config.luceneSearchNeedLogin = StringUtil.getBoolean(properties.getProperty(Config.getConfigLuceneSearchNeedLogin()), true);
            Config.canRepeatUrl = StringUtil.getBoolean(properties.getProperty(Config.getCanCanRepeatUrl()), true);
            Config.mail = properties.getProperty(Config.getConfigMail());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

    /**
     * 缓存时间，单位：s
     *
     * @return
     */
    private static String getConfigCacheTime() {
        return "web.cacheTime";
    }

    /**
     * 用户登录信息缓存时间
     *
     * @return
     */
    private static String getConfigLoginInforTime() {
        return "web.loginInforTime";
    }

    /**
     * 允许上传的文件大小
     *
     * @return
     */
    private static String getConfigFileSize() {
        return "web.fileSize";
    }

    /**
     * 允许上传的图片类型
     *
     * @return
     */
    private static String getConfigImageType() {
        return "web.imageType";
    }

    /**
     * 允许上传的文件类型
     *
     * @return
     */
    private static String getConfigFileType() {
        return "web.fileType";
    }

    /**
     * 是否开放注册
     *
     * @return
     */
    private static String getConfigOpenRegister() {
        return "web.openRegister";
    }

    /**
     * 全文索引是否需要登录才能使用
     *
     * @return
     */
    private static String getConfigLuceneSearchNeedLogin() {
        return "web.luceneSearchNeedLogin";
    }

    /**
     * 接口url是否能重复
     *
     * @return
     */
    private static String getCanCanRepeatUrl() {
        return "web.canRepeatUrl";
    }

    /**
     * 数据库
     *
     * @return
     */
    private static String getConfigMail() {
        return "mail.username";
    }

}
